import { createStoreBindings  } from "mobx-miniprogram-bindings";
import { store } from "../../Store/Store";
// pages/cart/cart.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
        cart:[],
        height:"",
        move:-1,
        time:null,
        winth:"",
        movwinth:0
  },
  touchMove(e){
    console.log(e)
    clearTimeout(this.data.time)
    this.data.movwinth=0
    var mov= this.data.movwinth
    console.log("mov="+mov)
    for (let index = 0; mov <= 50; index++) {
       mov= mov+5
      if(mov>50)
        return
      // mov=
      this.data.time=setTimeout(()=>{
       
        this.setData({
          move:e.currentTarget.dataset.index,
          movwinth:mov
        })
      },50)
      
    }
    
  },
  deletenull(){
    this.Alldelete()
    this.getLond()
  },
  selectjs(e){
    var index = e.currentTarget.dataset.index
    this.select(index)
    this.getLond()
  },
  delete(e){
    var index = e.currentTarget.dataset.index
    this.delecate(index)
    this.getLond()
  },
  comput(e){

  console.log(e)
  var index = e.currentTarget.dataset.index
  var symbol=Number(e.currentTarget.dataset.symbol)
  // console.log("1")
  this.addNumber(index,symbol)
  this.getLond()
},
clickgoods(e){
  wx.navigateTo({
    url: '/pages/goods_detail/main?goods_id='+e.target.dataset.id,
  })
  // console.log()
},
  /**
   * 生命周期函数--监听页面加载
   */
  getLond(){
    var than = this
    than.storeBindings = createStoreBindings(than, {
      store,
      fields: ["cart","getcart","number"],
      actions: ["update","addToCart","addNumber","delecate","select","Alldelete"],
    });
    than.setData({
      cart:store.getcart
    })
  },
  onLoad(options) {
   var than = this
   than.getLond()
   console.log(wx.getWindowInfo().safeArea)

   than.setData({
     height:wx.getWindowInfo().safeArea.height-250,
     winth:wx.getWindowInfo().safeArea.width
   })
  //  console.log)
    // console.log(store.cart)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})